package com.xbongbong.paas.help.subform.abstracts;

import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.saas.domain.entity.UserTeamEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * 团队es和数据库转化抽象类
 * @author 魏荣杰
 * @date 2020/8/20 13:47
 * @since
 * @version
 */
public abstract class AbstractUserTeamTransferSubForm extends AbstractTransferSubForm {

    public List<PaasFormDataEntity> transferTeamToFormDataList(List<? extends UserTeamEntity> userTeamEntities) {
        List<PaasFormDataEntity> paasFormDataEntities = new ArrayList<>();
        for (UserTeamEntity userTeamEntity : userTeamEntities) {
            PaasFormDataEntity paasFormDataEntity = transferTeamToFormData(userTeamEntity);
            paasFormDataEntities.add(paasFormDataEntity);
        }

        return paasFormDataEntities;
    };

    public abstract PaasFormDataEntity transferTeamToFormData(UserTeamEntity userTeamEntity);

    public List<? extends UserTeamEntity> transferFormDataToTeamList(List<PaasFormDataEntity> paasFormDataEntities) {
        List<UserTeamEntity> userTeamEntities = new ArrayList<>();
        for (PaasFormDataEntity paasFormDataEntity : paasFormDataEntities) {
            UserTeamEntity userTeamEntity = transferFormDataToTeam(paasFormDataEntity);
            userTeamEntities.add(userTeamEntity);
        }

        return userTeamEntities;
    };

    public abstract UserTeamEntity transferFormDataToTeam(PaasFormDataEntity paasFormDataEntity);

    public PaasFormDataEntity createPaasFormDataEntityForUserTeam(UserTeamEntity userTeamEntity) {
        PaasFormDataEntity paasFormDataEntity = new PaasFormDataEntity();
        paasFormDataEntity.setAddTime(userTeamEntity.getAddTime());
        paasFormDataEntity.setUpdateTime(userTeamEntity.getUpdateTime());
        paasFormDataEntity.setCorpid(userTeamEntity.getCorpid());
        paasFormDataEntity.setDel(userTeamEntity.getDel());
        paasFormDataEntity.setId(userTeamEntity.getId());
        return paasFormDataEntity;
    };

//    public void formatDataForEs(JSONObject teamJson, JSONObject data, String dbAttr, String dataAttr, Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        if (Objects.nonNull(fieldTypeEnum)) {
//            switch (fieldTypeEnum) {
//                case TEXT:
//                    data.put(dataAttr, teamJson.getString(dbAttr));
//                    break;
//                case NUM:
//                case DATETIME:
//                    data.put(dataAttr, teamJson.getLong(dbAttr));
//                    break;
//                default:
//            }
//        }
//    }
//
//    public void formatDataForDb(JSONObject data, JSONObject dbData, String dbAttr, String dataAttr, Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        if (Objects.nonNull(fieldTypeEnum)) {
//            Object value = data.get(dataAttr);
//            if (Objects.nonNull(value)) {
//                switch (fieldTypeEnum) {
//                    case TEXT:
//                        dbData.put(dbAttr, value.toString());
//                        break;
//                    case NUM:
//                    case DATETIME:
//                        dbData.put(dbAttr, Long.valueOf(value.toString()));
//                        break;
//                    default:
//                }
//            }
//        }
//    }

}
